
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  // 确认选择的爱好
  sureChoose(e){
    let activeHobby = []
    let _t = this
    let hobbyList = _t.data.hobbyList
    for (let i = 0; i < hobbyList.length;i++){
      if (hobbyList[i].active == true){
        activeHobby.push(hobbyList[i])
      }
    }
    activeHobby = activeHobby
    wx.setStorageSync('hobby', activeHobby)
    _t.setData({
      activeHobby: activeHobby
    }) 
    wx.navigateBack({
      delta: 1,
    })
  },
  chooseHobby(e){
    console.log(e)
    let index = e.currentTarget.dataset.index
    let _t = this
    let hobbyList = _t.data.hobbyList
    hobbyList[index].active = !hobbyList[index].active
    _t.setData({
      hobbyList: hobbyList
    })
  },

  onLoad: function (t) {
    let _t = this
    getApp().request({
      url: getApp().api.hobby.hobby,
      success: function (t) {
        console.log(t)
        let hobbyList = t.data
        for (let i = 0; i < hobbyList.length;i++){
          hobbyList[i].active = false
        }        
        _t.setData({
          hobbyList: hobbyList
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setNavigationBarTitle({
      title: '爱好选择',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})